import yhTools from "@/tools/yh";
import { InterfaceG } from "@config/Config";
import store from "@/Redux/Store/Store";
import { Toast } from "antd-mobile";

/**获取face++的token */
async function face_getFaceBizToken() {
	Toast.loading("加载中...", 100);
	let objs = {
		url: InterfaceG.face_getFaceBizToken,
		params: { productNo: "601" }
	};
	let resp = await yhTools.request(objs);
	Toast.hide();
	if (resp.code === "0") {
		const token = resp.data.bizToken;
		return token;
	} else {
		Toast.info(resp.message, 2);
		return "";
	}
}

const startLiveFace = async data => {
	console.log("场景4。。。");
	let { authHeaderStr, lnid, applyNo, devicesInfo, userName, idNo } = data;
	//1.0.6版本替换Face++
	let bizToken = "";
	if (yhTools.isHigherVersion()) {
		// 1.0.6版本
		bizToken = await face_getFaceBizToken();
	}
	let params = {
		needUpload: true,
		url: yhTools.isHigherVersion()
			? InterfaceG.face_authAndSubmitCreditV2
			: InterfaceG.xhf_credit_faceAndSubmitApply,
		header: authHeaderStr, //头部信息
		bizToken,
		params: {
			bizToken,
			userName,
			idNo,
			lnid,
			channelCode: "YHB",
			applyNo,
			productNo: "601",
			userDeviceInfo: JSON.stringify(devicesInfo)
		},
		_alertShow: false
	};
	let resp = await yhTools.startLiveFace(params);
	return resp;
};

export default {
	startLiveFace
};
